<#assign menu="event_add">
<#include "/system/head.ftl">
<link rel="stylesheet" type="text/css" href="http://developer.amap.com/Public/css/demo.Default.css"/>
<script language="javascript" src="http://webapi.amap.com/maps?v=1.3&key=0124fded525ed5c45b8bc81d43a0db5a"></script>
<!--main content start-->
<section id="main-content">
    <section class="wrapper">
        <!-- page start-->

        <form id="fileForm" action="${basePath}/admin/event/add.json" autocomplete="off" method="post">
            <div class="row">
                <input type="hidden" name="pic" id="pic"/>

                <div class="col-lg-9">
                    <section class="panel">
                        <header class="panel-heading"> 活动title</header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 活动title</header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 人均消费
                        </header>
                        <div class="panel-body">
                            <select name="perCapita" class="form-control">
                                <option>免费</option>
                                <option><100</option>
                                <option>101~300</option>
                                <option>301~500</option>
                                <option>501~800</option>
                                <option>>800</option>
                            </select>
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 开始时间(例如:2014-11-10 10:10)
                        </header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="startTime">
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 活动地址;
                        </header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="address" id="address">
                        </div>
                        <div class="form-group">
                            <button class="btn btn-shadow btn-primary" type="button" onClick="geocoder()">获取经纬度</button>
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 经度;
                        </header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="longitude" id="longitude">
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 纬度;
                        </header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="latitude" id="latitude">
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 购票地址
                        </header>
                        <div class="panel-body">
                            <input type="text" class="form-control" name="ticketUrl">
                        </div>
                    </section>

                    <section class="panel">
                        <header class="panel-heading"> 活动类型
                        </header>
                        <div class="panel-body">
                            <select name="type" class="form-control">
                                <option>聚餐</option>
                                <option>棋牌</option>
                                <option>游戏</option>
                                <option>派对</option>
                                <option>K歌</option>
                                <option>会议</option>
                                <option>旅行</option>
                                <option>演出</option>
                                <option>运动</option>
                                <option>艺术</option>
                                <option>逛街</option>
                            </select>
                        </div>
                    </section>

                    <section class="panel">
                        <header class="panel-heading"> 活动图片 (请确认只上传一张)</header>
                        <div class="panel-body">
                            <div id="attachment"></div>
                            <button id="file_upload" class="btn btn-shadow btn-info" type="button"><i
                                    class="icon-cloud-upload"></i> 添加附件
                            </button>
                        </div>
                    </section>
                    <section class="panel">
                        <header class="panel-heading"> 活动描述</header>
                        <div class="panel-body">
                            <script id="content" name="description" type="text/plain"
                                    style="width: 100%; height: 260px;"></script>
                            <script type="text/javascript">
                                var contentEditor;
                                $(function () {
                                    contentEditor = UE.getEditor('content');
                                });
                            </script>
                        </div>
                    </section>
                </div>
                <div class="form-group">
                    <button class="btn btn-shadow btn-primary" type="submit">发布</button>
                </div>
            </div>
        </form>
        <!-- page end-->
    </section>
</section>
<!--main content end-->
<script type="text/javascript">
    var kindId = "${kindId}";
    var kind = "article";
    $.extend({
        getAttachment: function () {
            $.getJSON("${basePath}/admin/attachment/list.json?kindId=" + kindId + "&v=" + Math.random(), function (data) {
                $('#attachment').html("");
                $.addAttachment(data.attachmentList);
            });
        },
        addAttachment: function (list) {
            console.log(list);
            var html = '<table class="table"><thead><tr><th>文件名</th><th>链接</th><th>大小</th><th>操作</th></tr></thead><tbody>';

            for (i = 0; i < list.length; i++) {
                var attachment = list[i];
                html += '<tr>';
                if (attachment.type == "photo") {
                    html += '<td><img src="' + attachment.path + '" width="200"/></td>';
                } else {
                    html += '<td>' + attachment.name + '</td>';
                }
                html += '<td>' + attachment.link + '</td><td>' + attachment.size + '</td><td>';
                html += '<a href="javascript:void(0);" title="删除" name="' + attachment.name + '" class="btn btn-danger btn-xs js_delete" attachmentId="' + attachment.attachmentId + '">删除</a> ';
                html += '</td></tr>';
                $("#pic").val(attachment.link);
            }
            html += '</tbody></table>';
            $('#attachment').prepend(html);
            $('#attachment .js_delete').click(function () {
                var file = $(this);
                bootbox.confirm("是否要删除【" + $(this).attr("name") + "】文件？", function (result) {
                    if (result) {
                        $.post("${basePath}/admin/attachment/delete.json", {'attachmentId': file.attr("attachmentId")}, function (data) {
                            if (data.result) {
                                $.getAttachment();
                            }
                        }, "json");
                    }
                });
            });
            $('#attachment .js_status').click(function () {
                $.post("${basePath}/admin/attachment/update_status.json", {
                    'attachmentId': $(this).attr("attachmentId"),
                    'status': $(this).attr("status")
                }, function (data) {
                    if (data.result) {
                        $.getAttachment();
                    }
                }, "json");
            });
            $('#attachment .js_link').click(function () {
                var attachmentId = $(this).attr("attachmentId");
                bootbox.prompt("为此附件增加链接", function (result) {
                    if (result != "") {
                        $.post("${basePath}/admin/attachment/update_link.json", {
                            'attachmentId': attachmentId,
                            'link': result
                        }, function (data) {
                            if (data.result) {
                                $.getAttachment();
                            }
                        }, "json");
                    }
                });
            });
        }
    });
    $(function () {
        $('#fileForm').ajaxForm({

            success: function (data) {
                if (data.result) {
                    bootbox.alert("保存成功");
                } else {
                    bootbox.alert(data.msg);
                }
            },
            error: function (data) {

            }
        });
        $('#file_upload').uploadify({
            'buttonText': '请选择文件',
            'swf': '${basePath}/system/assets/uploadify/uploadify.swf',
            'uploader': '${basePath}/admin/attachment/upload.json;jsessionid=${JSESSIONID}',
            'formData': {'kindId': kindId, 'kind': kind},
            'fileObjName': 'file',
            'fileTypeExts': '*.*',
            'method': 'post',
            'onUploadSuccess': function (file, data, response) {
                $.getAttachment();
            }
        });
        $.getAttachment();
    });
</script>

<script language="javascript">
    var mapObj;
    var marker = new Array();
    var windowsArr = new Array();

    mapObj = new AMap.Map("iCenter");

    function geocoder() {
        var MGeocoder;
        //加载地理编码插件
        mapObj.plugin(["AMap.Geocoder"], function () {
            MGeocoder = new AMap.Geocoder({
                radius: 5000 //范围，默认：500
            });
            //返回地理编码结果
            AMap.event.addListener(MGeocoder, "complete", geocoder_CallBack);
            //地理编码
            MGeocoder.getLocation($("#address").val());
        });
    }
    //地理编码返回结果展示
    function geocoder_CallBack(data) {
        var resultStr = "";
        //地理编码结果数组
        var geocode = new Array();
        geocode = data.geocodes;
        console.log(data);
        $("#longitude").val(geocode[0].location.getLng());
        $("#latitude").val(geocode[0].location.getLat());

    }


</script>


<#include "/system/foot.ftl">
 